package com.system.web;

import com.common.utils.LoginInterceptor;
import com.common.utils.VisitInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfigurer implements WebMvcConfigurer {

  @Autowired
  private LoginInterceptor loginInterceptor;
  @Autowired
  private VisitInterceptor visitInterceptor;

//  private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
//          "classpath:/META-INF/resources/", "classpath:/resources/",
//          "classpath:/static/", "classpath:/public/" };

  /**
   * 添加静态资源文件，外部可以直接访问地址
   * @param registry
   */
  @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
      //其他静态资源，与本文关系不大
      //registry.addResourceHandler("/upload/**").addResourceLocations("file:"+ TaleUtils.getUplodFilePath()+"upload/");

      //需要配置1：----------- 需要告知系统，这是要被当成静态文件的！
      //第一个方法设置访问路径前缀，第二个方法设置资源路径
      //registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");

//      //增加jsp资源路径
//    if (!registry.hasMappingForPattern("/**")) {
//      registry.addResourceHandler("/**").addResourceLocations(
//              CLASSPATH_RESOURCE_LOCATIONS);
//    }
  }

  @Override
  public void addViewControllers(ViewControllerRegistry registry) {
      //registry.addViewController("/error/404").setViewName("/admin/page_error/error_404.html");
  }

  // 这个方法用来注册拦截器，我们自己写好的拦截器需要通过这里添加注册才能生效
  @Override
  public void addInterceptors(InterceptorRegistry registry) {
    // addPathPatterns("/**") 表示拦截所有的请求，
    // excludePathPatterns("/login", "/register") 表示除了登陆与注册之外，因为登陆注册不需要登陆也可以访问
    //String [] arrs= {"/htlogin","/htlogon", "/logout", "/test/**","/js/**", "/css/**","/js/**","/font/**","/fonts/**", "/image/**","/images/**"};
	//实际上只用放开这句代码即可

      //登录拦截器
	registry.addInterceptor(loginInterceptor).addPathPatterns("/**").excludePathPatterns("/t_news/saveT_news","/file/uploadFileDB","/upload/toUploadOneFile2","/t_order/saveT_order","/sanshuone","/sanshutwo","/sanshuthree","/htlogin","/htlogon","/ERROR", "/logout", "/test/**","/js/**", "/css/**","/jslogin/**","/easyui/**","/ckeditor/**","/bootstrap/**","/kindeditor/**","/font-awesome-4.7.0/**","/portal/**","/font/**","/fonts/**","/image/**","/images/**","/attached/**");

	//访问日志拦截器
	registry.addInterceptor(visitInterceptor).addPathPatterns("/**").excludePathPatterns("/t_order/saveT_order","/sanshuone","/sanshutwo","/sanshuthree","/htlogin","/htlogon","/ERROR", "/logout", "/test/**","/js/**", "/css/**","/jslogin/**","/font/**","/fonts/**","/image/**","/images/**","/attached/**");

    //相应时间大于5秒的方法 监控；
    // InterfaceInterceptor
  }
}
